package com.intelligent.mts.client.core.view;

import com.intelligent.mts.client.utils.ApplicationBeanUtils;
import com.intelligent.mts.client.utils.GBC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

/**
 * Created by Administrator on 2016/8/23.
 */
@Component
public class Main extends JPanel{

    @Autowired
    MainTabbed mainTabbed;

    @Autowired
    MainStatusPanel mainStatusPanel;

    @PostConstruct
    public void initComponent(){

        this.setLayout(new GridBagLayout());
        this.setPreferredSize(new Dimension(1000, 618));

        this.add(mainTabbed, new GBC(0,1).setFill(GBC.BOTH).setWeight(100, 5).setInsets(0,0,0,0));
        mainStatusPanel.setMinimumSize(new Dimension(0, 28));
        this.add(mainStatusPanel, new GBC(0, 4).setFill(GBC.BOTH).setWeight(100, 0));

        mainTabbed.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                int selectedIndex = mainTabbed.getSelectedIndex();

                if (selectedIndex == 1){
                    ApplicationBeanUtils.getBean(BomSearchPanel.class).initCustomer();
                }
                if (selectedIndex == 2){
                    ApplicationBeanUtils.getBean(TestPanel.class).initStationId();
                    ApplicationBeanUtils.getBean(TestPanel.class).initFgvalue();
                    ApplicationBeanUtils.getBean(TestPanel.class).reloadTable();
                }
            }
        });
    }
}
